/*-----------------------------------------------------------------------------
	The contents of this file are subject to the Mozilla Public License
	Version 1.1 (the "License"); you may not use this file except in
	compliance with the License.You may obtain a copy of the License at
	http://www.mozilla.org/MPL/MPL-1.1.html
	
	Software distributed under the License is distributed on an "AS IS"
	basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
	License for the specific language governing rights and limitations
	under the License.
	
	The Original Code is Fever Framework code.
	
	The Initial Developer of the Original Code is Romain Ecarnot.
	Portions created by Initial Developer are Copyright (C) 2006
	the Initial Developer. All Rights Reserved.
	
	Contributor(s):
	
	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
-----------------------------------------------------------------------------*/

import fever.app.accelerator.Keyboard;
import fever.app.accelerator.KeyDefinition;
import fever.utils.StringUtil;

/**
 * Allows definition of key sequence like (CTRL+S) to be 
 * use by {@link fever.app.accelerator.KeyboardController} controller.
 * 
 * <p>Example
 * {@code
 *	 var combo : KeyCombo = new KeyCombo( Keyboard.onKeyCONTROL, Keyboard.onKeyT )
 *	 controller.push( combo, new KeyComboCommand() );
 * }
 * 
 * @see fever.app.accelerator.KeyboardController
 * @see fever.app.accelerator.Keyboard
 * @see fever.app.accelerator.KeyDefinition
 * 
 * @author Romain Ecarnot
 */
class fever.app.accelerator.KeyCombo implements KeyDefinition
{
	//-------------------------------------------------------------------------
	// Constants definition
	//-------------------------------------------------------------------------
	
	/** Constant definition for concatenation character. */
	public static var LIMITER : String = "|";
	
	
	//-------------------------------------------------------------------------
	// Private properties
	//-------------------------------------------------------------------------
	
	private var _key : Keyboard;
	private var _combo : String;
	
	
	//-------------------------------------------------------------------------
	// Public Properties
	//-------------------------------------------------------------------------
	
	/** {@link fever.app.accelerator.Keyboard} instance created for this combo. */
	public function get key() : Keyboard { return _key; }
	
	/** Combo id. */	public function get combo() : String { return _combo; }
	
	/** Repetition delay for combo. */
	public function get delay() : Number { return _key.delay; }
	public function set delay( value ) { _key.delay = value; }
	
	
	//-------------------------------------------------------------------------
	// Public API
	//-------------------------------------------------------------------------
	
	/**
	 * Constructor.
	 * 
	 * @param ... Arguments chain is used to define sequence keys.
	 */
	public function KeyCombo( key : Keyboard )
	{
		var l : Number = arguments.length;
		var c : String = '';
		var comboName : String = '';
		
		for( var i : Number = 0; i < l; i++ )
		{
			var next : Keyboard = arguments[ i ];
			c += next;
			comboName += StringUtil.uppercaseFirst( next.getName() );
			
			if( i < l-1 ) 
			{
				c += LIMITER;
				comboName += "+";
			}
		}
		
		_key = new Keyboard( comboName );
		_combo = c;
	}
	
	/**
	 * Returns key definition name.
	 */
	public function getName() : String
	{
		return _key.name;	
	}
	
	/**
	 * {@link KeyCombo} stringifier.
	 * 
	 * @return {@code String} representation of instance
	 */
	public function toString() : String
	{
		return 'KeyCombo ' + _combo;	
	}
}